package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.AxiConfig;
import com.sailfish.springbootdemo.pojo.db2.AxiDataCache;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface AxiDataCacheDao {
    @Results(id = "axiDataCacheResultMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "product_level", property = "productLevel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_name", property = "productName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_line", property = "productLine", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcb_code", property = "pcbCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "panel_code", property = "panelCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "panel_name", property = "panelName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_status", property = "productStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "board_complexity", property = "boardComplexity", jdbcType = JdbcType.VARCHAR),
            @Result(column = "first_pass_yield", property = "firstPassYield", jdbcType = JdbcType.VARCHAR),
            @Result(column = "test_rate", property = "testRate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "test_project", property = "testProject", jdbcType = JdbcType.VARCHAR),
            @Result(column = "refresh_type", property = "refreshType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "refresh_type_detail", property = "refreshTypeDetail", jdbcType = JdbcType.INTEGER),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "table_type", property = "tableType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "project_version", property = "projectVersion", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "approve_status", property = "approveStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "approve_user_id", property = "approveUserId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "approve_user_name", property = "approveUserName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "table_type_old", property = "tableTypeOld", jdbcType = JdbcType.VARCHAR),
            @Result(column = "test_rate_old", property = "testRateOld", jdbcType = JdbcType.VARCHAR),
            @Result(column = "test_project_old", property = "testProjectOld", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_level_old", property = "productLevelOld", jdbcType = JdbcType.VARCHAR),
            @Result(column = "product_status_old", property = "productStatusOld", jdbcType = JdbcType.VARCHAR),
            @Result(column = "first_pass_yield_old", property = "firstPassYieldOld", jdbcType = JdbcType.VARCHAR),
            @Result(column = "send_mail", property = "sendMail", jdbcType = JdbcType.INTEGER),
            @Result(column = "delete_type", property = "deleteType", jdbcType = JdbcType.INTEGER),
    })
    /*
     * 查询单个
     */
    @Select("<script> " +
            "select * " +
            "from " + DB2TableName.AXI_DATA_CACHE +
            "<where> " +
            "<if test='approveStatus != null and approveStatus != \"\"'>" +
            " and approve_status = #{approveStatus}" +
            "</if>" +
            "</where> " +
            "</script>")
    List<AxiDataCache> getByApproveStatus(@Param("approveStatus") String approveStatus);

    @Select("<script> " +
            "select * " +
            "from " + DB2TableName.AXI_DATA_CACHE +
            "<where> " +
            "<if test='approveUserId != null and approveUserId != \"\"'>" +
            " and approve_user_id = #{approveUserId}" +
            "</if>" +
            "<if test='approveStatus != null and approveStatus != \"\"'>" +
            " and approve_status = #{approveStatus}" +
            "</if>" +
            "</where> " +
            "</script>")
    @ResultMap(value = "axiDataCacheResultMap")
    List<AxiDataCache> getByApproveUser(@Param("approveUserId") String approveUserId, @Param("approveStatus") String approveStatus);

    @Select("<script> " +
            "select distinct approve_user_id " +
            " from " + DB2TableName.AXI_DATA_CACHE +
            " where approve_status = '待审核'" +
            "</script>")
    List<String> getApproveUserList();
}
